package com.etool.action;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;

import com.etool.commons.utils.AjaxUtils;
import com.opensymphony.xwork2.ActionSupport;

public class TestAction extends ActionSupport{
	HttpServletResponse response=ServletActionContext.getResponse();
	
	
	@Action("json-data")
	public String jsonData()
	{
		List<Map<String, Object>> data=new ArrayList<Map<String,Object>>();
		
		Map<String, Object> map1=new HashMap<String, Object>();
		map1.put("name","男");
		map1.put("value","1");
		
		Map<String, Object> map2=new HashMap<String, Object>();
		map2.put("name","女");
		map2.put("value","2");
		
		data.add(map1);
		data.add(map2);
		
		AjaxUtils.writeJson(response, Collections.singletonMap("data", (Object)data));
		
		return NONE;
		
	}
	
	
	@Action("json-data-2")
	public String jsonData2()
	{
		List<Map<String, Object>> data=new ArrayList<Map<String,Object>>();
		
		Map<String, Object> map1=new HashMap<String, Object>();
		map1.put("parentValue", "1");
		map1.put("name","男1");
		map1.put("value","11");
		
		Map<String, Object> map2=new HashMap<String, Object>();
		map2.put("parentValue", "2");
		map2.put("name","女1");
		map2.put("value","21");
		
		Map<String, Object> map3=new HashMap<String, Object>();
		map3.put("parentValue", "2");
		map3.put("name","女2");
		map3.put("value","22");
		
		data.add(map1);
		data.add(map2);
		data.add(map3);
		
		AjaxUtils.writeJson(response, Collections.singletonMap("data", (Object)data));
		
		return NONE;
		
	}
}
